
use "$jfqa_rep/22_Forcerank_setup.dta", clear

qui{
*merge forcerank data
joinby ticker year month day using "$jfqa_rep/Forcerank.dta"

*adjust returns for contest
forval i=1/12 {
	egen mean_lag_`i'=mean(lag`i'_ret), by(contest_id)
	replace lag`i'_ret=lag`i'_ret-mean_lag_`i'
	drop mean_lag_`i'
}

drop if missing(convexity_4)
drop if missing(convexity_8)
drop if missing(convexity_12)
drop if missing(fut1_ret)

collapse points lag*, by(ticker contest_id start)

forval i=1/12 {
drop if missing(lag`i'_ret)
}

sort start ticker
}

*4 lags
nl (points = {b0} + ///
	{b1}*(({b2}*lag1_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4) + ///
		({b2}^2*lag2_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4) + ///
		({b2}^3*lag3_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4) + ///
		({b2}^4*lag4_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4))), ///
		initial(b0 0 b1 1 b2 0.5) nolog vce(cluster start)
test _b[/b2]=1
local b2 = sign(_b[/b2])
display "Ho: coef = 1, t-statistic = " , sqrt(r(F))

*8 lags
nl (points = {b0} + ///
	{b1}*(({b2}*lag1_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^2*lag2_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^3*lag3_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^4*lag4_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^5*lag5_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^6*lag6_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^7*lag7_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8) + ///
		({b2}^8*lag8_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8))), ///
		initial(b0 0 b1 1 b2 0.5) nolog vce(cluster start)
test _b[/b2]=1
local b2 = sign(_b[/b2])
display "Ho: coef = 1, t-statistic = " , sqrt(r(F))

*12 lags
nl (points = {b0} + ///
	{b1}*(({b2}*lag1_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^2*lag2_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^3*lag3_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^4*lag4_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^5*lag5_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^6*lag6_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^7*lag7_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^8*lag8_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^9*lag9_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^10*lag10_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^11*lag11_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12) + ///
		({b2}^12*lag12_ret)/({b2}+{b2}^2+{b2}^3+{b2}^4+{b2}^5+{b2}^6+{b2}^7+{b2}^8+{b2}^9+{b2}^10+{b2}^11+{b2}^12))), ///
		initial(b0 0 b1 1 b2 0.5) nolog vce(cluster contest)
test _b[/b2]=1
local b2 = sign(_b[/b2])
display "Ho: coef = 1, t-statistic = " , sqrt(r(F))
